package com.reliable.service.serviceimpl;

import com.reliable.service.domain.ReliableSyncWatermark;
import com.reliable.service.mapper.ReliableSyncWatermarkMapper;
import com.reliable.service.service.IReliableSyncWatermarkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.Date;

/**
 * 同步位点Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-11-10
 */
@Service
public class ReliableSyncWatermarkServiceImpl extends ServiceImpl<ReliableSyncWatermarkMapper, ReliableSyncWatermark> implements IReliableSyncWatermarkService {



    @Autowired
    private ReliableSyncWatermarkMapper watermarkMapper;

    @Override
    public Date getLastProcessedAt() {
        ReliableSyncWatermark watermark = watermarkMapper.selectById(1);
        if (watermark == null) {
            // 初始化
            watermark = new ReliableSyncWatermark();
            watermark.setId(1);
            watermark.setLastProcessedAt(new Date(1746163200000L)); // 2025-05-01 00:00:00
            watermarkMapper.insert(watermark);
            return watermark.getLastProcessedAt();
        }
        return watermark.getLastProcessedAt();
    }

    @Override
    public void updateLastProcessedAt(Date time) {
        ReliableSyncWatermark watermark = new ReliableSyncWatermark();
        watermark.setId(1);
        watermark.setLastProcessedAt(time);
        watermarkMapper.updateById(watermark);
    }
}